home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 30.5 KB | 913 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWStrs.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifdef FW_BUILD_MAC
- #include <Types.h>
- #endif
-
- #ifndef FWEXCLIB_H
- #include "FWExcLib.h"
- #endif
-
- #ifndef FWSTRS_H
- #include "FWStrs.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWSTRTOO_H
- #include "FWStrToo.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment Strings
- #endif
-
- //========================================================================================
- // CLASS FW_CByteString
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CByteString destructor
- //----------------------------------------------------------------------------------------
-
- FW_CByteString::~FW_CByteString()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteString default constructor
- //----------------------------------------------------------------------------------------
-
- FW_CByteString::FW_CByteString() :
- fRepresentation(0),
- fByteLength(0),
- fCapacity(0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteString copy constructor
- //----------------------------------------------------------------------------------------
-
- FW_CByteString::FW_CByteString(const FW_CByteString &string) :
- fRepresentation(0),
- fByteLength(0),
- fCapacity(0)
- {
- FW_UNUSED(string);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteString::AppendBytes
- //----------------------------------------------------------------------------------------
-
- void FW_CByteString::AppendBytes(const FW_Char* source, FW_ByteCount numberBytes)
- {
- InsertBytes(source, numberBytes, fByteLength);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteString::DeleteBytes
- //----------------------------------------------------------------------------------------
-
- void FW_CByteString::DeleteBytes(FW_ByteCount numberBytes, FW_ByteCount position)
- {
- FW_ASSERT(numberBytes >= 0);
- FW_ASSERT(position>=0 && position<=fByteLength);
- FW_ASSERT(position+numberBytes <= fByteLength);
- if (numberBytes > 0)
- {
- FW_Byte* atPosition = BytePositionInString(position);
- FW_ByteCount toMove = fByteLength-(position+numberBytes);
- FW_BlockMove(atPosition+numberBytes, atPosition, toMove);
- PrivSetByteLength(fByteLength - numberBytes);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteString::InsertBytes
- //----------------------------------------------------------------------------------------
-
- void FW_CByteString::InsertBytes(const FW_Char* bytes,
- FW_ByteCount numberBytes,
- FW_ByteCount position)
- {
- FW_ASSERT(bytes != NULL);
- FW_ASSERT(numberBytes >= 0);
- FW_ASSERT(position>=0 && position<=fByteLength);
- if (numberBytes > 0)
- {
- FW_ByteCount capacityNeeded = fByteLength+numberBytes;
- GrowCapacity(capacityNeeded);
- FW_ASSERT(fCapacity >= capacityNeeded);
-
- FW_Byte* blockToMove = BytePositionInString(position);
- FW_BlockMove(blockToMove,
- blockToMove+numberBytes,
- fByteLength-position+sizeof(FW_Char));
- FW_BlockMove((const FW_Byte*)bytes, blockToMove, numberBytes);
- PrivSetByteLength(capacityNeeded);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteString::ReplaceBytes
- //----------------------------------------------------------------------------------------
-
- void FW_CByteString::ReplaceBytes(const FW_Char* source,
- FW_ByteCount numberBytes,
- FW_ByteCount position)
- {
- FW_ASSERT(source != NULL);
- FW_ASSERT(numberBytes >= 0);
- FW_ASSERT(position>=0 && position<=fByteLength);
- if (numberBytes > 0)
- {
- FW_ByteCount bytesToReplace = FW_Minimum(numberBytes, fByteLength-position);
-
- FW_ByteCount capacityNeeded = fByteLength - bytesToReplace + numberBytes;
- FW_ByteCount capacity = GrowCapacity(capacityNeeded);
- FW_ASSERT(capacityNeeded <= capacity);
-
- FW_ByteCount bytesAtEndToMove = fByteLength - position - bytesToReplace;
- if (bytesAtEndToMove>0 && bytesToReplace!=numberBytes)
- {
- FW_BlockMove(BytePositionInString(position+bytesToReplace),
- BytePositionInString(position+numberBytes),
- bytesAtEndToMove);
- }
-
- FW_BlockMove((const FW_Byte*)source, BytePositionInString(position), numberBytes);
- PrivSetByteLength(capacityNeeded);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteString::ReplaceAllBytes
- //----------------------------------------------------------------------------------------
-
- void FW_CByteString::ReplaceAllBytes(const FW_Char* string, FW_ByteCount numberBytes)
- {
- ReplaceBytes(string, numberBytes, 0);
- TruncateBytes(numberBytes);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteString::RetrieveBytes
- //----------------------------------------------------------------------------------------
-
- void FW_CByteString::RetrieveBytes(FW_Char* destination,
- FW_ByteCount numberBytes,
- FW_ByteCount position) const
- {
- FW_ASSERT(destination != NULL);
- FW_ASSERT(numberBytes >= 0);
- FW_ASSERT(position>=0);
- FW_ASSERT(position+numberBytes <= fByteLength+1); // allow retrieval of NUL terminator
- const FW_Byte* rep = fRepresentation;
- const FW_Byte* start = rep + position;
- if (numberBytes > 0)
- FW_BlockMove(start, (FW_Byte*)destination, numberBytes);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteString::TruncateBytes
- //----------------------------------------------------------------------------------------
-
- void FW_CByteString::TruncateBytes(FW_ByteCount bytePosition)
- {
- if (bytePosition < fByteLength)
- DeleteBytes(fByteLength - bytePosition, bytePosition);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CByteString::PrivSetByteLength
- //----------------------------------------------------------------------------------------
-
- void FW_CByteString::PrivSetByteLength(FW_ByteCount bytes)
- {
- fByteLength = bytes;
- PrivNullTerminate();
- }
-
-
- //========================================================================================
- // CLASS FW_CString
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CString::~FW_CString
- //----------------------------------------------------------------------------------------
-
- FW_CString::~FW_CString()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::FW_CString (Default constructor)
- //----------------------------------------------------------------------------------------
-
- FW_CString::FW_CString() :
- FW_CByteString(),
- fLength(0),
- fCharWidth(sizeof(FW_Char))
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::FW_CString (Copy constructor)
- //----------------------------------------------------------------------------------------
-
- FW_CString::FW_CString(const FW_CString &string) :
- FW_CByteString(),
- fLength(0), // Derived class is responsible for updating cached lengths
- fCharWidth(sizeof(FW_Char))
- {
- FW_UNUSED(string);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::FW_CString (another constructor)
- //----------------------------------------------------------------------------------------
-
- FW_CString::FW_CString(FW_ByteCount charWidth) :
- FW_CByteString(),
- fLength(0),
- fCharWidth(charWidth)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CString& FW_CString::operator=(const FW_CString& string)
- {
- if (&string != this)
- {
- fCharWidth = string.GetCharWidth();
- ReplaceAll(string);
- }
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CString& FW_CString::operator=(const FW_Char* string)
- {
- ReplaceAllBytes(string, FW_StringLength(string));
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::operator[]
- //----------------------------------------------------------------------------------------
-
- FW_Char FW_CString::operator[](FW_CharacterPosition position) const
- {
- FW_Char ch;
- Retrieve(&ch, 1, position);
- return ch;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::CharsToBytes
- //----------------------------------------------------------------------------------------
-
- FW_ByteCount FW_CString::CharsToBytes(FW_CharacterCount numberChars,
- FW_CharacterPosition position,
- FW_ByteCount& bytePosition) const
- {
- bytePosition = position * fCharWidth;
- return numberChars * fCharWidth;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::Delete
- //----------------------------------------------------------------------------------------
-
- void FW_CString::Delete(FW_CharacterCount numberChars, FW_CharacterPosition position)
- {
- FW_ASSERT(numberChars >= 0);
- FW_ASSERT(position>=0 && position<=fLength);
- FW_ASSERT(position+numberChars <= fLength);
- if (numberChars > 0)
- {
- FW_ByteCount bytePosition;
- FW_ByteCount bytesToDelete = CharsToBytes(numberChars, position, bytePosition);
- DeleteBytes(bytesToDelete, bytePosition);
- PrivSetLength(fLength-numberChars);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::Insert
- //----------------------------------------------------------------------------------------
-
- void FW_CString::Insert(const FW_Char* chars,
- FW_CharacterCount numberChars,
- FW_CharacterPosition position)
- {
- FW_ASSERT(numberChars >= 0);
- FW_ASSERT(position>=0 && position<=fLength);
- if (numberChars > 0)
- {
- FW_ByteCount bytePosition;
- FW_ByteCount numberBytes = CharsToBytes(numberChars, position, bytePosition);
- InsertBytes(chars, numberBytes, bytePosition);
- PrivSetLength(fLength + numberChars);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::ReplaceAllBytes
- //----------------------------------------------------------------------------------------
-
- void FW_CString::ReplaceAllBytes(const FW_Char* string, FW_ByteCount numberBytes) // Override
- {
- FW_CByteString::ReplaceAllBytes(string, numberBytes);
- PrivSetLength(fByteLength/fCharWidth);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::Replace
- //----------------------------------------------------------------------------------------
-
- void FW_CString::Replace(const FW_Char* source,
- FW_CharacterCount numberChars,
- FW_CharacterPosition position)
- {
- FW_ASSERT(numberChars >= 0);
- FW_ASSERT(position>=0 && position<=fLength);
- if (numberChars > 0)
- {
- FW_CharacterCount charsToReplace = FW_Minimum(numberChars, fLength-position);
- FW_ByteCount bytePosition;
- FW_ByteCount numberBytes = CharsToBytes(numberChars, position, bytePosition);
-
- ReplaceBytes(source, numberBytes, bytePosition);
- PrivSetLength(fLength - charsToReplace + numberChars);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::ReplaceAll
- //----------------------------------------------------------------------------------------
-
- void FW_CString::ReplaceAll(const FW_CString& string)
- {
- FW_ASSERT(string.GetCharWidth() == fCharWidth); // ???
- Replace((const FW_Char*)string, string.GetLength(), 0);
- Truncate(string.GetLength());
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::ReplaceAll
- //----------------------------------------------------------------------------------------
-
- void FW_CString::ReplaceAll(const FW_Char* items, FW_CharacterCount numberItems)
- {
- ReplaceAllBytes(items, numberItems);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::ReplaceAll
- //----------------------------------------------------------------------------------------
-
- void FW_CString::ReplaceAll(const FW_Char* string)
- {
- ReplaceAllBytes(string, FW_StringLength(string));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::Retrieve
- //----------------------------------------------------------------------------------------
-
- void FW_CString::Retrieve(FW_Char* destination, FW_CharacterCount numberChars, FW_CharacterPosition position) const
- {
- FW_ASSERT(numberChars >= 0);
- FW_ASSERT(position>=0);
- FW_ASSERT(position+numberChars <= fLength+1); // allow retrieval of NUL terminator
- FW_ByteCount bytePosition;
- FW_ByteCount numberBytes = CharsToBytes(numberChars, position, bytePosition);
- RetrieveBytes(destination, numberBytes, bytePosition);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::PrivSetLength
- //----------------------------------------------------------------------------------------
-
- void FW_CString::PrivSetLength(FW_CharacterCount characters,
- FW_ByteCount bytes,
- FW_ByteCount charWidth)
- {
- fLength = characters;
- fCharWidth = charWidth;
- PrivSetByteLength(bytes);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::Truncate
- //----------------------------------------------------------------------------------------
-
- void FW_CString::Truncate(FW_CharacterPosition position)
- {
- FW_ByteCount bytePosition;
- CharsToBytes(0, position, bytePosition);
- TruncateBytes(bytePosition);
- PrivSetLength(position);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CString::ToUpper
- //----------------------------------------------------------------------------------------
-
- void FW_CString::ToUpper()
- {
- FW_CStringTool *tool = FW_CStringTool::GetCurrentStringTool();
- tool->ToUpper(*this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::ToLower
- //----------------------------------------------------------------------------------------
-
- void FW_CString::ToLower()
- {
- FW_CStringTool *tool = FW_CStringTool::GetCurrentStringTool();
- tool->ToLower(*this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::Substitute
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CString::Substitute(const FW_CString &searchString,
- const FW_CString &substitutionString)
- {
- FW_CStringTool *tool = FW_CStringTool::GetCurrentStringTool();
- return tool->Substitute(*this, searchString, substitutionString);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::FindSubString
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CString::FindSubString(const FW_CString &subString,
- FW_CharacterPosition &foundPosition,
- FW_CharacterPosition startPosition) const
- {
- FW_CStringTool *tool = FW_CStringTool::GetCurrentStringTool();
- return tool->FindSubString(*this, subString, foundPosition, startPosition);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::FindCharacter
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CString::FindCharacter(FW_Char character,
- FW_CharacterPosition &foundPosition,
- FW_CharacterPosition startPosition) const
- {
- FW_LChar longChar = character;
- return this->FindCharacter(longChar, foundPosition, startPosition);
- }
-
- FW_Boolean FW_CString::FindCharacter(FW_LChar character,
- FW_CharacterPosition &foundPosition,
- FW_CharacterPosition startPosition) const
- {
- FW_CStringTool *tool = FW_CStringTool::GetCurrentStringTool();
- return tool->FindCharacter(*this, character, foundPosition, startPosition);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::FindWhiteSpace
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CString::FindWhiteSpace(FW_CharacterPosition &foundPosition,
- FW_CharacterPosition startPosition) const
- {
- FW_CStringTool *tool = FW_CStringTool::GetCurrentStringTool();
- return tool->FindWhiteSpace(*this, foundPosition, startPosition);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::FindNonWhiteSpace
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CString::FindNonWhiteSpace(FW_CharacterPosition &foundPosition,
- FW_CharacterPosition startPosition) const
- {
- FW_CStringTool *tool = FW_CStringTool::GetCurrentStringTool();
- return tool->FindNonWhiteSpace(*this, foundPosition, startPosition);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::Compare
- //----------------------------------------------------------------------------------------
-
- int FW_CString::Compare(const FW_CString &string) const
- {
- FW_CStringTool *tool = FW_CStringTool::GetCurrentStringTool();
- return tool->CompareStrings(*this, string);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::operator==
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CString::operator==(const FW_CString &string) const
- {
- return (GetByteLength()==string.GetByteLength()) && (Compare(string) == kStringsEqual);
- }
-
- FW_Boolean FW_CString::operator==(const char *string) const
- {
- FW_CharacterCount stringLength = FW_StringLength(string);
-
- if (GetByteLength() != stringLength)
- return FALSE;
-
- FW_CDynamicString aString(string, stringLength);
-
- return Compare(aString) == kStringsEqual;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::operator!=
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CString::operator!=(const FW_CString &string) const
- {
- return (GetByteLength()!=string.GetByteLength()) || (Compare(string) != kStringsEqual);
- }
-
- FW_Boolean FW_CString::operator!=(const char *string) const
- {
- FW_CharacterCount stringLength = FW_StringLength(string);
-
- if (GetByteLength() == stringLength)
- return FALSE;
-
- FW_CDynamicString aString(string, stringLength);
-
- return Compare(aString) != kStringsEqual;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::operator<
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CString::operator<(const FW_CString &string) const
- {
- return Compare(string) == kStringOneLess;
- }
-
- FW_Boolean FW_CString::operator<(const char *string) const
- {
- FW_CharacterCount stringLength = FW_StringLength(string);
- FW_CDynamicString aString(string, stringLength);
-
- return Compare(aString) == kStringOneLess;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::operator>
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CString::operator>(const FW_CString &string) const
- {
- return Compare(string) == kStringOneGreater;
- }
-
- FW_Boolean FW_CString::operator>(const char *string) const
- {
- FW_CharacterCount stringLength = FW_StringLength(string);
- FW_CDynamicString aString(string, stringLength);
-
- return Compare(aString) == kStringOneGreater;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::operator<=
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CString::operator<=(const FW_CString &string) const
- {
- return Compare(string) != kStringOneGreater;
- }
-
- FW_Boolean FW_CString::operator<=(const char *string) const
- {
- FW_CharacterCount stringLength = FW_StringLength(string);
- FW_CDynamicString aString(string, stringLength);
-
- return Compare(aString) != kStringOneGreater;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString::operator>=
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CString::operator>=(const FW_CString &string) const
- {
- return Compare(string) != kStringOneLess;
- }
-
- FW_Boolean FW_CString::operator>=(const char *string) const
- {
- FW_CharacterCount stringLength = FW_StringLength(string);
- FW_CDynamicString aString(string, stringLength);
-
- return Compare(aString) != kStringOneLess;
- }
-
- //========================================================================================
- // CLASS FW_CDynamicString
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CDynamicString::~FW_CDynamicString
- //----------------------------------------------------------------------------------------
-
- FW_CDynamicString::~FW_CDynamicString()
- {
- FW_START_DESTRUCTOR
- delete [] fRepresentation;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDynamicString::FW_CDynamicString
- //----------------------------------------------------------------------------------------
-
- FW_CDynamicString::FW_CDynamicString(const FW_CDynamicString &string) :
- FW_CString()
- {
- fCharWidth = string.GetCharWidth();
- FW_ByteCount numberBytes = string.GetByteLength();
- AllocateRepresentation(numberBytes);
- Append(string);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDynamicString::FW_CDynamicString
- //----------------------------------------------------------------------------------------
-
- FW_CDynamicString::FW_CDynamicString(const FW_CString &string) :
- FW_CString()
- {
- fCharWidth = string.GetCharWidth();
- FW_ByteCount numberBytes = string.GetByteLength();
- AllocateRepresentation(numberBytes);
- Append(string);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDynamicString::FW_CDynamicString
- //----------------------------------------------------------------------------------------
-
- FW_CDynamicString::FW_CDynamicString(const FW_Char *items, FW_CharacterCount numberItems) :
- FW_CString()
- {
- FW_ByteCount numberBytes = FW_CharsToBytes(numberItems);
- AllocateRepresentation(numberBytes);
- Append(items, numberItems);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDynamicString::FW_CDynamicString
- //----------------------------------------------------------------------------------------
-
- FW_CDynamicString::FW_CDynamicString(const FW_Char *items)
- {
- FW_CharacterCount numberItems = FW_StringLength(items);
- FW_ByteCount numberBytes = FW_CharsToBytes(numberItems);
- AllocateRepresentation(numberBytes);
- Append(items, numberItems);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDynamicString::FW_CDynamicString
- //----------------------------------------------------------------------------------------
-
- FW_CDynamicString::FW_CDynamicString(FW_ByteCount capacity) :
- FW_CString()
- {
- AllocateRepresentation(capacity);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDynamicString::FW_CDynamicString
- //----------------------------------------------------------------------------------------
-
- FW_CDynamicString::FW_CDynamicString(FW_ByteCount capacity, FW_ByteCount charWidth) :
- FW_CString(charWidth)
- {
- AllocateRepresentation(capacity);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDynamicString::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CString& FW_CDynamicString::operator=(const FW_CDynamicString& string)
- {
- if (&string != this)
- {
- fCharWidth = string.GetCharWidth();
- ReplaceAll(string);
- }
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDynamicString::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CString& FW_CDynamicString::operator=(const FW_CString& string)
- {
- fCharWidth = string.GetCharWidth();
- ReplaceAll(string);
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDynamicString::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CString& FW_CDynamicString::operator=(const FW_Char* string)
- {
- ReplaceAllBytes(string, FW_StringLength(string));
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDynamicString::GrowCapacity
- //----------------------------------------------------------------------------------------
-
- FW_ByteCount FW_CDynamicString::GrowCapacity(FW_ByteCount capacityNeeded)
- {
- PrivResize(capacityNeeded);
- return fCapacity;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDynamicString::PrivResize
- //----------------------------------------------------------------------------------------
-
- void FW_CDynamicString::PrivResize(FW_ByteCount newCapacity)
- {
- if (fCapacity < newCapacity)
- {
- FW_Byte *newRep = new FW_Byte[newCapacity+sizeof(FW_Char)];
- FW_BlockMove(fRepresentation, newRep, fCapacity+sizeof(FW_Char));
- delete [] fRepresentation;
- fRepresentation = newRep;
- fCapacity = newCapacity;
- }
- }
-
- //========================================================================================
- // CLASS FW_CStringReader
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CStringReader::FW_CStringReader
- //----------------------------------------------------------------------------------------
-
- FW_CStringReader::FW_CStringReader(const FW_CString& string) :
- FW_CTextReader(string.fRepresentation,
- string.fRepresentation+string.GetByteLength(),
- string.GetByteLength())
- {
- fBytesPerChar = string.GetCharWidth();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStringReader::FW_CStringReader
- //----------------------------------------------------------------------------------------
-
- FW_CStringReader::FW_CStringReader( const FW_CString &string,
- FW_BytePosition start,
- FW_ByteCount length) :
- FW_CTextReader(string.fRepresentation+start,
- string.fRepresentation+start+length,
- length)
- {
- fBytesPerChar = string.GetCharWidth();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStringReader::FW_CStringReader
- //----------------------------------------------------------------------------------------
-
- FW_CStringReader::~FW_CStringReader()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStringReader::DoGetNextBuffer
- //----------------------------------------------------------------------------------------
-
- void FW_CStringReader::DoGetNextBuffer()
- {
- FW_ASSERT(FALSE); // one contiguous block, there is no next buffer
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStringReader::DoGetPreviousBuffer
- //----------------------------------------------------------------------------------------
-
- void FW_CStringReader::DoGetPreviousBuffer()
- {
- FW_ASSERT(FALSE); // one contiguous block, there is no previous buffer
- }
-
- //========================================================================================
- // CLASS FW_CStringWriter
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CStringWriter::FW_CStringWriter
- //----------------------------------------------------------------------------------------
-
- FW_CStringWriter::FW_CStringWriter( FW_CString &string,
- FW_TextWriterMode mode,
- unsigned short bufferSize) :
- FW_CTextWriter(0, 0),
- fString(string),
- fBufferSize(bufferSize),
- fMode(mode)
- {
- fBuffer = new FW_Byte[fBufferSize];
- fStart = fBuffer;
- fNext = fBuffer;
- fLimit = fBuffer + fBufferSize;
- if (mode == FW_kTextAppend)
- fBufferSum = string.GetByteLength();
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStringWriter::~FW_CStringWriter
- //----------------------------------------------------------------------------------------
-
- FW_CStringWriter::~FW_CStringWriter()
- {
- FW_START_DESTRUCTOR
- FlushAndUpdateText();
- delete [] fBuffer;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStringWriter::DoFlushBuffer
- //----------------------------------------------------------------------------------------
-
- void FW_CStringWriter::DoFlushBuffer(FW_ByteCount bytesToFlush) // Override
- {
- FW_CString& string = fString; // MetroWerks bug workaround [AMB]
-
- if (bytesToFlush > 0)
- {
- if (fMode == FW_kTextWriteOver)
- string.Replace((FW_Char*) fBuffer, bytesToFlush, fBufferSum);
- else // (fMode == FW_kTextAppend)
- string.Append((FW_Char*) fBuffer, bytesToFlush);
- fNext = fBuffer; // reset next pointer so buffer looks empty
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStringWriter::DoGetNextBuffer
- //----------------------------------------------------------------------------------------
-
- void FW_CStringWriter::DoGetNextBuffer() // Override
- {
- fNext = fBuffer; // we only use one buffer, so just reset fNext to the start
- }
-